package com.ruoyi.web.controller.pc.forms;


import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.web.domain.vo.FormsVo;
import com.ruoyi.web.domain.vo.QueryVo;
import com.ruoyi.web.service.IFormsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;


@RestController
@RequestMapping("/forms/forms")
public class FormsController extends BaseController {

    @Autowired
    private IFormsService formsService;

    @PreAuthorize("@ss.hasPermi('forms:forms:list')")
    @GetMapping("/list")
    public TableDataInfo list(QueryVo queryVo) {

        if(!StringUtils.isEmpty(queryVo.getQIds1())){
            queryVo.setQId1(queryVo.getQIds1().get(queryVo.getQIds1().size()-1));
        }
        if(queryVo.getQTimeStart() == null){
            Date date = new Date();
            queryVo.setQYear(DateUtils.getYear(date));
            queryVo.setQQuarter(DateUtils.getQuarter(date));
        }else{
            Date date = DateUtils.parseDate(queryVo.getQTimeStart());
            queryVo.setQYear(DateUtils.getYear(date));
            queryVo.setQQuarter(DateUtils.getQuarter(date));
        }
        startPage();
        List<FormsVo> list = formsService.listByPage(queryVo);
        return getDataTable(list);

    }




    @GetMapping("/list1")
    public TableDataInfo list1(QueryVo queryVo) {

        if(!StringUtils.isEmpty(queryVo.getQIds1())){
            queryVo.setQId1(queryVo.getQIds1().get(queryVo.getQIds1().size()-1));
        }
        if(queryVo.getQTimeStart() == null){
            Date date = new Date();
            queryVo.setQYear(DateUtils.getYear(date));
//            queryVo.setQQuarter(DateUtils.getQuarter(date));
        }else{
            Date date = DateUtils.parseDate(queryVo.getQTimeStart());
            queryVo.setQYear(DateUtils.getYear(date));
//            queryVo.setQQuarter(DateUtils.getQuarter(date));
        }
        List<FormsVo> list = formsService.listByPage1(queryVo);
        return getDataTable(list);

    }

}

